#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define ERROR -999

typedef int ElementType;
typedef int Position;
struct QNode
{
    ElementType* Data;
    Position Front, Rear;
    int MaxSize;
};
typedef struct QNode* PtrToQNode;
typedef PtrToQNode Queue;

Queue CreateQueue(int MaxSize)
{
    Queue Q = (Queue) malloc(sizeof(struct QNode));
    Q->Data = (ElementType*) malloc(MaxSize *sizeof(ElementType));
    Q->Front = Q->Rear = 0;
    Q->MaxSize = MaxSize;
    return Q;
}

bool IsEmpty(Queue Q)
{
    return Q->Front == Q->Rear;
}

bool IsFull(Queue Q)
{
    return (Q->Rear + 1) % Q->MaxSize == Q->Front;
}

bool Enqueue(Queue Q, ElementType X)
{
    if (IsFull(Q)) {
        printf("队列满\n");
        return false;
    }

    Q->Rear = (Q->Rear + 1) % Q->MaxSize;
    Q->Data[Q->Rear] = X;
    return true;
}

ElementType Dequeue(Queue Q)
{
    if (IsEmpty(Q)) {
        printf("队列空\n");
        return ERROR;
    }

    Q->Front = (Q->Front + 1) % Q->MaxSize;
    return Q->Data[Q->Front];
}